import 'package:flutter/material.dart';
import 'package:wallpaper/components/input/normal_input.dart';
import 'package:wallpaper/generated/l10n.dart';

class MySearchInput extends StatelessWidget {
  final TextEditingController controller;
  final ValueChanged<String>? onSubmitted;
  final String? title;
  const MySearchInput(
      {super.key, required this.controller, this.onSubmitted, this.title});

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context).colorScheme;
    return Container(
      padding: EdgeInsets.all(5),
      color: theme.primaryContainer,
      child: Row(
        children: [
          if (title != null)
            Padding(
              padding: const EdgeInsets.only(left: 8, right: 5),
              child: RichText(
                text: TextSpan(
                  style: TextStyle(
                    letterSpacing: 2,
                    color: theme.onSurface,
                  ),
                  children: [
                    TextSpan(
                      text: title?.substring(0, 1),
                      style: TextStyle(
                        fontWeight: FontWeight.bold,
                        fontSize: 20,
                      ),
                    ),
                    TextSpan(
                      text: title?.substring(1, title!.length),
                      style: TextStyle(
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ],
                ),
                softWrap: true,
              ),
            ),
          Expanded(
            child: NormalInput(
              height: 34,
              controller: controller,
              title: S.of(context).a8,
              onSubmitted: onSubmitted,
            ),
          ),
          GestureDetector(
            onTap: () {
              FocusScope.of(context).requestFocus(FocusNode());
              Navigator.pop(context);
            },
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: Text(
                '取消',
                style: TextStyle(fontSize: 16),
              ),
            ),
          ),
        ],
      ),
    );
  }
}
